﻿namespace Facade
{
    internal class HtmlWriter
    {
        private readonly StreamWriter writer;
        public HtmlWriter(StreamWriter writer)
        {
            this.writer = writer;
        }

        public void Title(string title)
        {
            this.writer.WriteLine("<html>");
            this.writer.WriteLine("<head>");
            this.writer.WriteLine($"<title>{title}</title>");
            this.writer.WriteLine("</head>");
            this.writer.WriteLine("<body>\n");
            this.writer.WriteLine($"<h1>{title}</h1>");
        }

        public void Paragraph(string msg)
        {
            this.writer.WriteLine($"<p>{msg}</p>\n");
        }

        public void Link(string href, string caption)
        {
            this.Paragraph($"<a href=\"{href}\">{caption}</a>");
        }

        public void Mailto(string mailAddr, string userName)
        {
            this.Link($"mailto:{mailAddr}", userName);
        }

        public void Close() 
        {
            this.writer.Write("</body>");
            this.writer.Write("</html>");
            this.writer.Close();
        }
    }
}
